﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>会员设置-微街秀管理后台</title>
    <script src="../js/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script src="../js/base.js" type="text/javascript"></script>
    <script src="../js/ajax-data.js" type="text/javascript"></script>
    <script src="../js/dialog.js" type="text/javascript"></script>
    <script src="../js/DatePicker/zh-cn/WdatePicker.js" type="text/javascript"></script>
     <style>
        table{border-collapse: collapse;border: none;width: 600px;}
        td{border: solid #ccc 1px;color:Black; height:36px; padding-left:10px;}
        td a{ text-decoration:none;}
    </style>
</head>
<body>
<div style="width:980px; margin-left:auto; margin-right:auto;">
<h2 style="width:600px; text-align:center;">会员设置</h2>
  <table id="list">
        <tr>
            <td style="width:130px;">会员ID：</td>
            <td id="id"> </td>
        </tr>
        <tr>
            <td>用户名：</td>
            <td id="name"> </td>
        </tr>
        <tr>
            <td>昵称：</td>
            <td id="nick_name"> </td>
        </tr>
        <tr>
            <td>会员版本：</td>
            <td>
                <select id="version">
                    <option selected="selected">请选择</option>
                 
                </select> 
            </td>
        </tr>
        <tr>
            <td>开始时间：</td>
            <td><input type="text" id="date" name="date" onfocus="WdatePicker()"/></td>
        </tr>
        <tr>
            <td>过期时间：</td>
            <td><input type="text" id="end_date" name="end_date" onfocus="WdatePicker()" /></td>
        </tr>
        <tr>
            <td colspan="2" style="text-align:center"><input type="button" id="sumit" value="提 交" /><input type="button" value="返 回" style="margin-left:20px;" onclick="javascript:history.go(-1)" /></td>
        </tr>
    </table>
</div>

<script>
    $(function () {
        var uid = getUrlArgStr("user_id");
        AjaxStart("../ajax/version.ashx?getlist", "", LoadSysVersion);
        AjaxStart("../ajax/user.ashx?getdetail", "user_id=" + uid, LoadUser);
    })
    $("#sumit").bind("click", function () {
        if (!checked()) return;
        ajax.getAjax("../ajax/userversion.ashx?add", "userid=" + $("#id").html() + "&version=" + $("#version").find("option:selected").attr("id") + "&data=" + $("#date").val() + "&endata=" + $("#end_date").val(), function (data) {
            if (data.code == "0") {
                Alert("保存成功");
                history.go(-1)
            }
            else { Alert(data.msg.toString()); }
        });
    });
   
    function checked() {
        if ($("#date").val() == "") {
            Alert("填写开始时间");
            return false;
        }
        if ($("#end_date").val() == "") {
            Alert("填写过期时间");
            return false;
        }
        if ($("#version").find("option:selected").attr("id") == undefined) {
            Alert("选择套餐");
            return false;
        }
        var time1 = new Date($("#date").val().replace("-", "/").replace("-", "/"));
        var time2 = new Date($("#end_date").val().replace("-", "/").replace("-", "/"));
        if (time2 < time1) {
            Alert("过期时间不能小于开始时间");
            return false;
        }
 
        return true;
    }
    function LoadUser(data) {
        if (data.code == 0) {
            $("#id").html(data.item.id);
            $("#nick_name").html(data.item.nick_name);
            $("#date").val(new Date().toLocaleDateString().replace("年", "-").replace("月", "-").replace("日", ""));
            $("#end_date").val(data.item.end_date);
        }
    }
    function LoadSysVersion(data) {
        if (data.code == 0) {
            for (var i = 0; i < data.item.length; i++) {
                $("#version").append("<option id='" + data.item[i].id + "'>" + data.item[i].name + "</option>");
            }
        }
    }
    function LoadVersion() {
        if (data.code == 0) {
            if (date.item != null) {
                
            }
        }
    }
</script>
</body>
</html>
